function reloadData(dataList,type) {
        var realTable=null;
        if (type=='buy'){
            realTable = $('#example_buy').DataTable();
        }
        if (type=='fail_buy'){
            realTable = $('#example_fail_buy').DataTable();
        }
        if (type=='sell'){
            realTable = $('#example_sell').DataTable();
        }
        var currentPage = realTable.page();
        realTable.clear();
        realTable.rows.add(dataList);
        realTable.page(currentPage).draw( false );
    }

function changeDisplay(type){
        if (type=='buy'){
             $("#div_buy").show();
             $('#div_fail_buy').hide();
             $("#div_sell").hide();
        }
        if (type=='fail_buy'){
             $("#div_buy").hide();
             $('#div_fail_buy').show();
             $("#div_sell").hide();
        }
        if (type=='sell'){
             $("#div_buy").hide();
             $('#div_fail_buy').hide();
             $("#div_sell").show();
        }
    }

function loadDate(){
        $.getJSON("/json",function (data) {
            var tradeDayList=data.trade_day;
            for (var i=0;i<tradeDayList.length;i++){
                var date=tradeDayList[i];
                if (i==tradeDayList.length-1){
                    var html_str = "<option selected='selected' value='" + date + "'>" + date + "</option>";
                }else{
                    var html_str = "<option value='" + date + "'>" + date + "</option>";
                }
                $('#trade_date').append(html_str);
            }
        })
        $.getJSON("/strategyJson",function (data) {
            var strategyList=data.strategy_list;
            var strategyNameList = data.strategy_name_list;
            for (var i=0;i<strategyList.length;i++){
                var strategy = strategyList[i];
                var strategyName = strategyNameList[i] ;

                var html_str = "<option value='" + strategy + "'>" + strategyName + "</option>";
                $('#strategy_name').append(html_str);

            }
        })

    }

function refreshBuySellInfo(type){
    var timeValue=$("#trade_date").val();
    $.ajax({
        url:"/buySellInfo",
        async:true,
        type:'POST',
        data:JSON.stringify({'date':timeValue,'type':type}),
        dataType:'json',
        success:function(result){
            var conditionValue=$("#strategy_name").val();
            var buySell=$("#buy_or_sell").val();
            var obj = result;
            reloadData(obj[conditionValue+'_'+buySell],buySell);
            changeDisplay(buySell);
        }
    });
}
